package com.ez.supervise.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.jexl.Expression;
import org.apache.commons.jexl.ExpressionFactory;
import org.apache.commons.jexl.JexlContext;
import org.apache.commons.jexl.JexlHelper;

import com.ez.supervise.model.sys.Permission;

import freemarker.template.Configuration;
@SuppressWarnings("unchecked")
public class MenuUtil {
    public static String ITEMS_EMPTY = "items : []";
    public static String MAIN_MENU_TEMPLATE = "{id : '${mainMenu.resId}'," +
	    "title : \"<label class=\'font_menu_a\'>${mainMenu.resName}</label>\"," + "border : false," +
	    "iconCls : 'icon-nav'," + ITEMS_EMPTY + "}";

    public static String SUB_MENU_TEMPLATE = "{id : '${subMenu.id}',"
	    + "title : \"<a href=javascript:createTab('result-') class='font_menu_b'>${subMenu.name}</a>\","
	    + "iconCls : 'icon-menu'," + "border : false}";

//    {
//	id : 'menu_base',
//	title : "<label class='font_menu_a'>指标设置</label>",
//	border : false,
//	iconCls : 'icon-nav',
//	items : [{
//		id : 'menu_base_goalcategory',
//		title : "<a href=javascript:createTab('goalcategory-" + (windIndex) + "') class='font_menu_b'>指标目录</a>",
//		iconCls : 'icon-menu',
//		border : false,
//		items : [{
//			id : 'menu_base_goalcategory',
//			id : 'menu_base_goaldetail',
//			title : "<a href=javascript:createTab('goaldetail-" + (windIndex)
//					+ "') class='font_menu_b'>指标细则管理</a>",
//			iconCls : 'icon-menu',
//			border : false,
//			items : [{
//				id : 'menu_base_orgchecksetting',
//				title : "<a href=javascript:createTab('orgchecksetting-" + (windIndex)
//						+ "') class='font_menu_b'>被考核部门指标设置</a>",
//				iconCls : 'icon-menu',
//				border : false
//			}]
//		}]
//	}]
//
//    }
    
    public static void testFreemarker(){
	Map map = new HashMap();
	Permission maniMenu = new Permission();
	maniMenu.setId(1L);
	maniMenu.setResId("menu_base");
	
	maniMenu.setResType("main_menu");
	maniMenu.setResName("基础信息");
	map.put("mainMenu", maniMenu);
	FreemarkerUtil.putTemplate(MAIN_MENU_TEMPLATE);
	FreemarkerUtil.putTemplate(SUB_MENU_TEMPLATE);
	String  result = FreemarkerUtil.processTemplate(MAIN_MENU_TEMPLATE,map);
	System.out.println(result);
	
    }
    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
	
	testFreemarker();
	// Create an expression object
	String jexlExp = "9*(1+2)";
	Expression e = (Expression) ExpressionFactory.createExpression(jexlExp);

	// Create a context
	JexlContext jc = JexlHelper.createContext();

	// Now evaluate the expression, getting the result
//	Object result = e.evaluate(jc);
	Object result = e.evaluate(jc);

	System.out.println("result:" + result);
	System.out.println("result type:" + result.getClass().getName());

	// assertEquals(((Long) result).intValue(), 27);
    }

}
